package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dto.Page;
import com.qf.entity.Employee;
import com.qf.mapper.EmpolyeeMapper;
import com.qf.service.EmpolyeeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EmployeeServiceImpl implements EmpolyeeService {
    @Resource
    private EmpolyeeMapper empolyeeMapper;
    @Override
    public List<Employee> getALLemp() {

        return empolyeeMapper.getALLemp();
    }



    @Override
    public void addEmpolyee(Employee employee) {
        empolyeeMapper.addEmpolyee(employee);
    }

    @Override
    public Employee findEmpolyeeById(Integer empId) {
        return empolyeeMapper.findEmpolyeeById(empId);
    }

    @Override
    public void updateEmpolyee(Employee employee) {
        System.out.println(employee);
        empolyeeMapper.updateEmpolyee(employee);
    }

    @Override
    public void deleteEmpolyee(Integer empId) {
            empolyeeMapper.deleteEmpolyee(empId);
    }

    /**
     * 分页查询
     *
     * */
    @Override
    public Page<Employee> getEmployeePage(int pageNo, int pageSize) {
        Page<Employee> page=new Page<>();
        PageHelper.startPage(pageNo,pageSize);
        List<Employee> employees = empolyeeMapper.getEmployeePage();
        PageInfo<Employee>   pageInfo=new PageInfo<>(employees);

        page.setPage(pageInfo.getList());//设置页中获取的数据
        page.setPageCount(pageInfo.getPages());//设置总页数
        page.setPageNo(pageInfo.getPageNum());//设置当前页
        page.setHasnext(pageInfo.isHasNextPage());//是否有下一页
        page.setHasPre(pageInfo.isHasPreviousPage());//是否有上一页

        return page;
    }
}
